//var mariasql = require("mariasql");
var db = require("../MariaDb");

var AccountController = AccountController || {};

AccountController = {
    AuthenticateUser : function AuthenticateUser(userId) {
        console.log("--------------------------------------------------------------------------------");
        console.log("In AccountController.js");
        
        console.log(db);
        
        db.set_database(
            'localhost',
            'root',
            'password',
            'project_radar'
        );
        
        db.query("SELECT * FROM user_account;", null, null, function(err, res) {
            console.log("in callback");
            console.log(res);
            // console.log(b);
            // console.log(c);
            
            console.log("result length: " + res.length);
            var idx = 0;
            for (idx = 0; idx < res.length; idx++) {
                console.log(res[idx].email);
            }
            if (err)
                throw err;
                  
            console.dir(res);
            
        });
        
        db.query("CALL add_user_account(:id, :password_hash, :password_salt, :creator_id, :created_datetime, :modifier_id, :modified_datetime);",  
        {
            id : userId,
            password_hash : 'password_hash',
            password_salt : 'password_salt',
            creator_id : 'SYSTEM',
            created_datetime : null, 
            modifier_id : null, 
            modified_datetime : null
            
        }, null,  function (err, res) {
            console.log('called');
            if (err)
                console.dir(err);
                //throw err;
            console.dir(res);
            
        });
        
        
        console.log("at return true");
        return true;
    } 
};

module.exports = AccountController;